#include <linux/sysfs.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kobject.h>
#include <linux/device.h>
#include "testcls.h"


//创建有class的设备,会在/sys/class/testcls下出现Obj2ofTestCls对象,它有属性:
//  /sys/devices/virtual/testCls/Obj1ofTestCls/testAttr
//static  struct class *cls;
static  struct device *devc;

static ssize_t test_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	printk("HanJ %s:%s\n" ,__FILE__, __func__ ) ;	
    return 0 ;
}

static ssize_t test_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
    printk("HanJ %s:%s\n" ,__FILE__ , __func__ ) ;	
	return count;
}

static DEVICE_ATTR(testAttr, 0664, test_show, test_store);

static int __init my_init(void)
{	
	int ret = 0;
	struct class *cls;
	printk("HanJ getTestCls\n" ) ;
	cls = getTestCls();
    printk("HanJ %s:%s getTestCls return %x\n" , __FILE__, __func__ , (unsigned int)cls ) ;
	//create device
    devc = device_create(cls,NULL,0,NULL, "Obj1ofTestCls");  
	printk("HanJ device_create return %x\n" , (unsigned int)devc ) ;
    ret = device_create_file( devc, &dev_attr_testAttr );
	printk("HanJ %s:%s  device_create_file return %d\n" ,__FILE__, __func__ , ret ) ;
	
	return ret ;
}


static void __exit my_exit(void)
{
	printk("HanJ exit\n" );
}

module_init(my_init);
module_exit(my_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Your Name");
MODULE_DESCRIPTION("Example of using kernfs");

